package com.meowcook.mapper;

import com.meowcook.pojo.dto.CommentDTO;
import com.meowcook.pojo.po.Comment;
import com.meowcook.pojo.vo.CommentVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28792
 * Date: 2025-05-17
 * Time: 16:31
 */
@Mapper(componentModel = "spring")
public interface CommentPojoMapper {
    CommentPojoMapper INSTANCE = Mappers.getMapper(CommentPojoMapper.class);

    @Mappings({
            @Mapping(source = "userId", target = "userId"),
            @Mapping(source = "recipeId", target = "recipeId"),
            @Mapping(source = "content", target = "content")
    })
    Comment toPO(CommentDTO commentDTO);

    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "content", target = "content"),
            @Mapping(source = "likeCount", target = "likeCount"),
            @Mapping(source = "replyCount", target = "replyCount"),
            @Mapping(source = "createTime", target = "createTime"),
            @Mapping(source = "author.id", target = "author.id"),
            @Mapping(source = "author.nickname", target = "author.nickname"),
            @Mapping(source = "author.avatarUrl", target = "author.avatarUrl"),
            @Mapping(source = "author.isAdmin", target = "author.isAdmin")
    })
    List<CommentVO> toVO(List<Comment> commentList);
}
